home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Source Code / Mark Pilgrim / Ghost 1.0 / source / Ghost ƒ / MSG Shell ƒ / msg menus.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-10-30  |  6.7 KB  |  318 lines  |  [TEXT/KAHL]

  1. /**********************************************************************\
  2.  
  3. File:        msg menus.c
  4.  
  5. Purpose:    This module handles menu selections, including selection
  6.             of dimmed menu items (hehe).
  7.  
  8.  
  9. Ghost -=- a classic word-building challenge
  10. Copyright (C) 1993 Mark Pilgrim
  11.  
  12. This program is free software; you can redistribute it and/or modify
  13. it under the terms of the GNU General Public License as published by
  14. the Free Software Foundation; either version 2 of the License, or
  15. (at your option) any later version.
  16.  
  17. This program is distributed in the hope that it will be useful,
  18. but WITHOUT ANY WARRANTY; without even the implied warranty of
  19. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  20. GNU General Public License for more details.
  21.  
  22. You should have received a copy of the GNU General Public License
  23. along with this program in a file named "GNU General Public License".
  24. If not, write to the Free Software Foundation, 675 Mass Ave,
  25. Cambridge, MA 02139, USA.
  26.  
  27. \**********************************************************************/
  28.  
  29. #include "msg graphics.h"
  30. #include "msg menus.h"
  31. #include "msg sounds.h"
  32. #include "msg prefs.h"
  33. #include "msg environment.h"
  34. #include "ghost globals.h"
  35. #include "ghost load-save.h"
  36. #include "ghost.h"
  37. #include "ghost dictionary.h"
  38. #include "ghost challenge.h"
  39.  
  40. Boolean            gMenuEnabled;
  41. MenuHandle        gAppleMenu;
  42. MenuHandle        gFileMenu;
  43. MenuHandle        gEditMenu;
  44. MenuHandle        gOptionsMenu;
  45. MenuHandle        gHelpMenu;
  46. MenuHandle        gComputerMenu;
  47. MenuHandle        gIntelligenceMenu;
  48. MenuHandle        gSpeedMenu;
  49. MenuHandle        gDictionaryMenu;
  50.  
  51. extern    long        menuDisable : 0x0b54;
  52.  
  53. void AdjustMenus(void)
  54. {
  55.     WindowPeek    theWindow;
  56.     int            kind;
  57.     int            i;
  58.     
  59.     theWindow = (WindowPeek)FrontWindow();
  60.     kind = theWindow ? theWindow->windowKind : 0;
  61.     
  62.     if(kind < 0)
  63.         EnableItem(gEditMenu, 0);
  64.     else
  65.         DisableItem(gEditMenu, 0);
  66.     
  67.     if(theWindow)
  68.         EnableItem(gFileMenu, closeItem);
  69.     else
  70.         DisableItem(gFileMenu, closeItem);
  71.     
  72.     if (gInProgress)
  73.     {
  74.         EnableItem(gFileMenu, saveItem);
  75.         EnableItem(gFileMenu, saveAsItem);
  76.         DisableItem(gFileMenu, newItem);
  77.         DisableItem(gFileMenu, openItem);    
  78.         DisableItem(gComputerMenu, 0);
  79.         DisableItem(gDictionaryMenu, 0);
  80.         DisableItem(gIntelligenceMenu, 0);
  81.         if (gTheWord[0]>0x01)
  82.             EnableItem(gOptionsMenu, challengeWord);
  83.         else
  84.             DisableItem(gOptionsMenu, challengeWord);
  85.     }
  86.     else
  87.     {
  88.         DisableItem(gFileMenu, saveItem);
  89.         DisableItem(gFileMenu, saveAsItem);
  90.         EnableItem(gFileMenu, newItem);
  91.         EnableItem(gFileMenu, openItem);
  92.         EnableItem(gComputerMenu, 0);
  93.         EnableItem(gDictionaryMenu, 0);
  94.         EnableItem(gIntelligenceMenu, 0);
  95.         DisableItem(gOptionsMenu, challengeWord);
  96.     }
  97.     
  98.     for (i=1; i<=6; i++)
  99.         CheckItem(gComputerMenu, i, (gNumComputerPlayers==i-1));
  100.     for (i=1; i<=3; i++)
  101.         CheckItem(gIntelligenceMenu, i, (gComputerIntelligence==i));
  102.     for (i=1; i<=5; i++)
  103.         CheckItem(gSpeedMenu, i, (gGameSpeed==5-i));
  104.     
  105.     CheckItem(gDictionaryMenu, 1, !gUseFullDictionary);
  106.     CheckItem(gDictionaryMenu, 2, gUseFullDictionary);
  107.     
  108.     CheckItem(gOptionsMenu, soundToggle, gSoundToggle&&gSoundAvailable);
  109.     CheckItem(gOptionsMenu, showMessage, gShowMessageBox);
  110.     
  111.     if (gSoundAvailable)
  112.         EnableItem(gOptionsMenu, soundToggle);
  113.     else
  114.         DisableItem(gOptionsMenu, soundToggle);
  115. }
  116.  
  117. void HandleMenu(long mSelect)
  118. {
  119.     int            menuID = HiWord(mSelect);
  120.     int            menuItem = LoWord(mSelect);
  121.     
  122.     if (menuID==0)
  123.     {
  124.         menuID=HiWord(menuDisable);
  125.         menuItem=LoWord(menuDisable);
  126.         gMenuEnabled=FALSE;
  127.     }
  128.     else gMenuEnabled=TRUE;
  129.     menuDisable=0L;
  130.  
  131.     switch (menuID)
  132.     {
  133.         case appleMenu:
  134.             HandleAppleMenu(menuItem);
  135.             break;
  136.         case fileMenu:
  137.             HandleFileMenu(menuItem);
  138.             break;    
  139.         case editMenu:
  140.             HandleEditMenu(menuItem);
  141.             break;
  142.         case optionsMenu:
  143.             HandleOptionsMenu(menuItem);
  144.             break;
  145.         case helpMenu:
  146.             HandleHelpMenu(menuItem);
  147.             break;
  148.         case computerMenu:
  149.             HandleComputerMenu(menuItem);
  150.             break;
  151.         case intelligenceMenu:
  152.             HandleIntelligenceMenu(menuItem);
  153.             break;
  154.         case speedMenu:
  155.             HandleSpeedMenu(menuItem);
  156.             break;
  157.         case dictionaryMenu:
  158.             HandleDictionaryMenu(menuItem);
  159.             break;
  160.       }
  161. }
  162.  
  163. void HandleAppleMenu(int menuItem)
  164. {
  165.     GrafPtr        savePort;
  166.     Str255        name;
  167.     
  168.     if(menuItem == 1)
  169.         ShowInformation();
  170.     if (menuItem == 2)
  171.         ShowSplashScreen();
  172.     else if(menuItem > 3)
  173.     {
  174.         GetPort(&savePort);
  175.         GetItem(gAppleMenu, menuItem, name);
  176.         OpenDeskAcc(name);
  177.         SetPort(savePort);
  178.     }
  179. }
  180.  
  181. void HandleFileMenu(int menuItem)
  182. {
  183.     Point            where;
  184.     SFTypeList        typeList;
  185.     SFReply            reply;
  186.     WindowPtr        theWindow;
  187.     int                i;
  188.     
  189.     switch (menuItem)
  190.     {
  191.         case newItem:
  192.             if (gMenuEnabled)
  193.                 NewGame();
  194.             else DoSound(sound_fluff, TRUE);
  195.             break;
  196.         case openItem:
  197.             if (gMenuEnabled)
  198.                 LoadSaveDispatch(TRUE, FALSE);
  199.             else DoSound(sound_fluff, TRUE);
  200.             break;
  201.         case closeItem:
  202.             if (gMenuEnabled)
  203.             {
  204.                 theWindow=FrontWindow();
  205.                 for (i=0; i<NUM_HELP; i++)
  206.                     if (theWindow == gHelp[i])
  207.                         gHelp[i]=0L;
  208.                 
  209.                 if(theWindow == gMainWindow)
  210.                     CloseMainWindow();
  211.                 else
  212.                     DisposeWindow(theWindow);
  213.                 
  214.                 AdjustMenus();
  215.             }
  216.             else DoSound(sound_fluff, TRUE);
  217.             break;
  218.         case saveItem:
  219.             if (gMenuEnabled)
  220.                 LoadSaveDispatch(FALSE, TRUE);
  221.             else DoSound(sound_fluff, TRUE);
  222.             break;
  223.         case saveAsItem:
  224.             if (gMenuEnabled)
  225.                 LoadSaveDispatch(FALSE, FALSE);
  226.             else DoSound(sound_fluff, TRUE);
  227.             break;
  228.         case quitItem:
  229.             gDone = TRUE;
  230.             break;
  231.     }
  232. }
  233.  
  234. void HandleEditMenu(int menuItem)
  235. {
  236.     if ((menuItem>0) && (menuItem!=2))
  237.         if (gMenuEnabled)
  238.         {
  239.             if(!SystemEdit(menuItem - 1))
  240.                 if(menuItem == undoItem)
  241.                     GameUndo();
  242.         }
  243.         else DoSound(sound_fluff, TRUE);
  244. }
  245.  
  246. void HandleOptionsMenu(int menuItem)
  247. {
  248.     switch (menuItem)
  249.     {
  250.         case saveOptions:
  251.             SaveThePrefs();
  252.             break;
  253.         case soundToggle:
  254.             gSoundToggle=!gSoundToggle;
  255.             DoSound(sound_on, TRUE);
  256.             break;
  257.         case showMessage:
  258.             gShowMessageBox=!gShowMessageBox;
  259.             if (gMainWindow)
  260.                 UpdateBoard();
  261.             break;
  262.         case challengeWord:
  263.             if (gMenuEnabled)
  264.                 ChallengeWord();
  265.             else DoSound(sound_fluff, TRUE);
  266.             break;
  267.     }
  268. }
  269.  
  270. void HandleComputerMenu(int menuItem)
  271. {
  272.     if ((menuItem>0) && (menuItem<=6))
  273.     {
  274.         if (gMenuEnabled)
  275.             gNumComputerPlayers=menuItem-1;
  276.         else DoSound(sound_fluff, TRUE);
  277.     }
  278. }
  279.  
  280. void HandleIntelligenceMenu(int menuItem)
  281. {
  282.     if ((menuItem>0) && (menuItem<=3))
  283.     {
  284.         if (gMenuEnabled)
  285.             gComputerIntelligence=menuItem;
  286.         else DoSound(sound_fluff, TRUE);
  287.     }
  288. }
  289.  
  290. void HandleSpeedMenu(int menuItem)
  291. {
  292.     if ((menuItem>0) && (menuItem<=5))
  293.     {
  294.         if (gMenuEnabled)
  295.             gGameSpeed=5-menuItem;
  296.         else DoSound(sound_fluff, TRUE);
  297.     }
  298. }
  299.  
  300. void HandleDictionaryMenu(int menuItem)
  301. {
  302.     if ((menuItem>0) && (menuItem<=2))
  303.     {
  304.         if (gMenuEnabled)
  305.             gUseFullDictionary=(menuItem==2);
  306.         else DoSound(sound_fluff, TRUE);
  307.     }
  308. }
  309.  
  310. void HandleHelpMenu(int menuItem)
  311. {
  312.     if ((menuItem>0) && (menuItem<=NUM_HELP))
  313.     {
  314.         OpenHelpWindow(menuItem-1);
  315.         SelectWindow(gHelp[menuItem-1]);
  316.     }
  317. }
  318.